package com.itzyf.pokemondata

import android.content.Context
import androidx.multidex.MultiDex
import cn.jpush.android.api.JPushInterface
import com.avos.avoscloud.AVOSCloud
import com.from.view.swipeback.SwipeBackHelper
import com.itzyf.pokemondata.activity.MainActivity
import com.tencent.bugly.Bugly
import com.tencent.bugly.beta.Beta
import com.tydic.baselibrary.BaseApplication
import com.tydic.baselibrary.BuildConfig
import org.litepal.LitePal


/**
 * @author 依风听雨
 * @version 创建时间：2018/12/24 14:06
 */
class App : BaseApplication() {

    override fun onCreate() {
        super.onCreate()
        AVOSCloud.setServer(AVOSCloud.SERVER_TYPE.API, "http://lc.pokemondds.cn")
        AVOSCloud.initialize(
            this,
            "vOm5cHrgDtRYkCeDnGuGfXzA-gzGzoHsz",
            "vn5rkMUf2Y56dzFjFEzaFq8L"
        )
        AVOSCloud.setDebugLogEnabled(BuildConfig.DEBUG)

        JPushInterface.setDebugMode(BuildConfig.DEBUG)
        JPushInterface.init(this)

        JPushInterface.setChannel(this,"push")

        val tags: MutableSet<String> = mutableSetOf()
        //0 不需要推送，1所有推送，2，狩猎场推送，3活动推送
        val sp = getSharedPreferences("config", Context.MODE_PRIVATE)

        //狩猎场消息
        if (sp.getBoolean("isHuntingPush", true)) {
            tags.add("hunting")
        }
        //活动爆料消息
        if (sp.getBoolean("isActivityPush", true)) {
            tags.add("history")
        }
        if (tags.size > 0)
            JPushInterface.setTags(this, 1, tags)

        Bugly.init(applicationContext, "cd88c0c274", BuildConfig.DEBUG)
        Beta.initDelay = 1 * 1000
        Beta.canShowUpgradeActs.add(
            MainActivity::
            class.java
        )

        LitePal.initialize(this)

        SwipeBackHelper.init(this)

//        Stetho.initializeWithDefaults(this)
    }

    override fun attachBaseContext(base: Context?) {
        super.attachBaseContext(base)
        //因为引用的包过多，实现多包问题
        MultiDex.install(this)
    }
}
